<template>
  <div>
    <el-container>
      <el-header>&nbsp;人力资源管理系统</el-header>
      <el-container class="container">
        <el-aside width="300px">
          <Menu>

          </Menu>
        </el-aside>

        <el-container>
          <el-main>
            <el-row>
              <el-col :span="22">
                <div class="grid-content bg-purple-dark">
                  <span>
                    个人信息查看
                  </span>
                </div>
              </el-col>
              <el-col :span="2">
                <div class="grid-content">
                  <el-button type="success" round @click="logOut">登出</el-button>
                </div>
              </el-col>
            </el-row>

            <el-row>
              <el-col :span="6">
                <div class="grid-content bg-purple">
                <span>
                  账号
                </span>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="grid-content bg-purple-light">
                  <el-input v-model="loginFile.uid" disabled/>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="grid-content bg-purple">
                <span>
                  姓名
                </span>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="grid-content bg-purple-light">
                  <el-input v-model="loginFile.uname" disabled/>
                </div>
              </el-col>
              </el-row>

            <el-row>
              <el-col :span="6">
                <div class="grid-content bg-purple">
                <span>
                  密码
                </span>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="grid-content bg-purple-light">
                  <el-input v-model="loginFile.upassword" disabled/>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="grid-content bg-purple">
                <span>
                  岗位
                </span>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="grid-content bg-purple-light">
                  <el-input v-model="loginFile.upost" disabled/>
                </div>
              </el-col>
            </el-row>
          </el-main>
        </el-container>

      </el-container>
    </el-container>
  </div>
</template>

<script>
import{ defineComponent, ref }from 'vue'
import { reactive, watch, onMounted } from 'vue';
import store from '@/store';
import { computed } from 'vue';
import { useStore } from 'vuex';

import {
  Location,
  Document,
  Menu as IconMenu,
  Setting,
} from '@element-plus/icons-vue'
import Menu from "@/components/Menu";
import {ElMessage} from "element-plus";
export default defineComponent({
  name: "PersonalInformation",
  components: {
    Menu,
    Location,
    Document,
    Setting,
    IconMenu,
  },
  setup() {
    const activeNames = ref(['1'])
    const handleChange = (val) => {
      console.log(val)
    }
    const store = useStore();
    const user = computed(() => store.state.user);
    console.log(user);
    const loginFile = reactive({
      uid: '',
      uname: '',
      upassword: '',
      upost: '',
    });

    // 使用 watch 来监听 user 的变化，并更新 loginFile
    watch(user, (newUser, oldUser) => {
      if (newUser) {
        loginFile.uid = newUser.uid;
        loginFile.uname = newUser.uname;
        loginFile.upassword = newUser.upassword;
        loginFile.upost = newUser.upost;
      }
    }, { immediate: true }); // { immediate: true } 确保在 watch 创建时立即执行一次
    return {
      input: ref(''),
      textarea: ref(''),
      activeNames,
      handleChange,
      loginFile,
    }
  },
  data() {
    return {
    }
  },
  methods: {
    logOut(){
      this.$store.dispatch('logout');
      alert("已登出")
      this.$router.push("/")
    }
  }
})
</script>

<style scoped>
.el-header{
  background-color: #409EFF;
  color: #e9eef3;
  text-align: left;
  line-height: 60px;
  font-size: 30px;
}
.el-aside {
  background-color: #d3dce6;
  color: var(--el-text-color-primary);
  text-align: center;
  /*line-height: 860px;*/
}

.el-main {
  background-color: #e9eef3;
  color: var(--el-text-color-primary);
  text-align: center;
  line-height: 30px;
}

body > .el-container {
  margin-bottom: 400px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.el-row {
  margin-bottom: 20px;
}

.el-row :last-child {
  margin-bottom: 0;
}

.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}

.high-row{
  min-height: 200px;
}

.container{
  min-height: 860px;
}

.line {
  width: 70%;
}

.line div {
  width: 100%;
  height: 0;
  border-top: 1px solid var(--el-border-color-base);
}

.photo-box{
  display: flex;
  width:100%;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
}
.left{
  width:75%;
}
.right {
  width: 25%;
  display: flex;
  flex-direction: column; /* 垂直排列子元素 */
  align-items: center; /* 水平居中子元素 */
  justify-content: center; /* 垂直居中子元素 */
  max-height: 100%;

}

.photo-upload-container {
  text-align: center;

}

.uploaded-image-container {
  width: 170px; /* 固定宽度 */
  display: flex;
  flex-direction: column; /* 垂直排列子元素 */
  align-items: center; /* 水平居中子元素 */
  text-align: center; /* 确保内部元素水平居中 */
}

.uploaded-image {
  width: 100%;
  height: 100%;

}
</style>